package com.yc.springmvc.web;

import com.yc.springmvc.bean.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

// 全局异常拦截
@Component
// 控制器增强注解 ==> AOP
@ControllerAdvice
public class MyExceptionHandler {
    // 异常拦截
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        e.printStackTrace();
        return new Result(0,e.getMessage(),null);
    }
}
